package JDK8;

import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class TraverSingMap {

    public static void main(String[] args) {
        System.out.println("知识点：asList  stream   filter  collect");
        List<String> list1 = Arrays.asList("abc","def","", "cbd", "", "ghi");
        System.out.println("------------1去空--------");
        List<String> filtered = list1.stream().filter(x -> x != "").collect(Collectors.toList());
        for(String s: filtered){
            System.out.println(s);
        }

        System.out.println("-----------2、输出----------");
        System.out.println("知识点：forEach limit排序   ---》 直接输出，没有返回值");
        Random random = new Random();
        random.ints().limit(3).forEach(System.out::println);

        System.out.println("-------------3、去重 distinct-------------");
        List<Integer> list2 = Arrays.asList(1,2,3,4,1,2,3);
        List<Integer> map = list2.stream().map(i -> i*2).distinct().collect(Collectors.toList());
        for(int m : map){
            System.out.println(m);
        }

        System.out.println("------------sorted 对流进行排序");
        List<Integer> list3 = Arrays.asList(4,8,9,2,7,3,5,6,1,10);
        list3.stream().sorted().forEach(System.out::println);


    }
}
